<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <script src="vue.js"></script>
    <title>Document</title>
    <style>
        .star{
            display: inline-block;
        }
        #box{
            border: 1px solid #000;
            margin: 20px 0;
            position: relative;
        }
        .star-line{
            position: absolute;
            /* top: 0; */
            overflow: hidden;

        }
    </style>
</head>
<body>
    <main id="app">
        <input type="text" v-model='count'>
        <star-com v-model='count' :total='total'
        :size='size'></star-com>
    </main>
    <script id="star" type="text/html">
        <main :style='mainStyle' id='box'>
            <div  class='star-line'>
                <span @click='changeValue(index)' 
                class='star' :style='starStyle' 
                v-for='index in total'>☆</span>
            </div>
            <div class='star-line' :style='blackStyle'>
                <span @click='changeValue(index-1)' class='star' 
                :style='starStyle'
                 v-for='index in total'>★</span>
            </div>
        </main>
    </script>
    <script>
        Vue.component('star-com',{
            template:'#star',
            props:{
                total:{
                type:Number,
                default:10
                },
                size:{
                    type:Number,
                    default:50
                },
                value:{}
               
            }
            ,
           
            computed:{
                starStyle:function(){
                    return {
                        width:this.size +'px',
                        height: this.size+'px',
                        fontSize:this.size+'px'
                    }
                },
                mainStyle:function(){
                    return {
                        width:this.total*this.size+'px',
                        height:this.size*1.4+'px'
                    }
                },
                blackStyle:function(){
                    return {
                        width:this.value *this.size +'px',
                        height:this.size*1.4+'px'
                    }
                }
            },
            methods:{
                changeValue:function(index){
                    this.$emit('input',index)
                }
            }
        })
        var vue =new Vue({
            el:'#app',
            data:{
                count:1,
                total:5,
                size:50,
            }
        })
    </script>
</body>
</html>